<template>
    <div class="searchbar">
        <input type="text" v-model="keywords" class="keywrods" placeholder="请输入作者或者编号" />
        <input type="submit" class="submit" value="搜索" @click="searchFun"/>
    </div>
</template>
<style scoped>
  .searchbar{
    border:0.03rem solid rgb(217,0,60);
    border-radius:0.1rem;
    margin:0.2rem 0;
  }
  .searchbar .keywrods{
    border:0;
    background:#fff;
    outline:0;
    width:70%;
    height:0.4rem;
    border-radius:0.1rem 0 0 0.1rem;
    padding:0 0.15rem;
  }
  .searchbar .submit{
    border:0;
    background:rgb(217,0,60);
    color:#fff;
    width:30%;
    float:right;
    height:0.4rem;
    font-weight: bolder;
    font-size:0.18rem;
  }
</style>
<script>
  export default {
    data(){
            return{
                keywords:""
            }
    },
    methods:{
      searchFun:function(){
      if(this.keywords===""){
           alert("关键词不能为空！");
           return false;
        }
        if(!isNaN(this.keywords)){
           this.axios.get("/api/vote/1/candidate?number="+this.keywords).then((response) => {
              if(response.data.code===200){
                    this.$emit('search-result',response.data.object);
               }else{
                    alert(response.data.message);
               }
            })
        }else{
           this.axios.get("/api/vote/1/candidate?realName="+this.keywords).then((response) => {
              if(response.data.code===200){
                    this.$emit('search-result',response.data.object);
               }else{
                    alert(response.data.message);
               }
            })
        }


      }
    }
  }
</script>
